﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace model
{
    class BoatCommands
    {
        public Boat Boat
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }
    
        public void registerBoat(model.Boat boat)
        {
            using (var db = new MemberContext())
            {
                db.Boats.Add(boat);
                db.SaveChanges();
            }
        }

        public void deleteBoat(model.Boat boat)
        {
            using (var db = new MemberContext())
            {
                var deleteBoat = db.Boats.Find(boat.boatId);
                db.Boats.Remove(deleteBoat);
                db.SaveChanges();
            }
        }

        public void updateBoat(model.Boat updatedBoat)
        {
            using (var db = new MemberContext())
            {
                var original = db.Boats.Find(updatedBoat.boatId);

                if (original != null)
                {
                    db.Entry(original).CurrentValues.SetValues(updatedBoat);
                    db.SaveChanges();
                }
            }
        }

        public List<model.Boat> getAllBoats()
        {
            using (var db = new MemberContext())
            {
                return db.Boats
                    .Include("Member")
                    .ToList();
            }
        }
    }
}
